/**
 * 添加收藏
 */

    GoodsCollection();
    function  GoodsCollection() {
        var bOff = true;
        var showTipTime = null;
        var oBtn_collection = $('.js_btn_collection ');   // 收藏按钮
        var oTip_collection = $('.js_tip_collection ');   // 收藏提示
        var oleaderShare = $('.js_btn_share');            // 分享按钮
        var oleaderBg = $('.js_leaderBg');                // 引导背景
        // 消息集合框
        var oIconList = $('.js_IconList');
        var oIconBtn = $('.js_IconBtn');

        oBtn_collection.on('click', function (e) {
            if(bOff) {
                bOff = false;
                var _url = '';
                var _off = '';
                if($(this).hasClass('active')) {
                    //_url = "/shop/goodsCollection/cancelCollection";
                    _url = "/m/g/goods/collection/1.0/collectGoods?flag=false";
                    _off = false;
                } else {
                    //_url = "/shop/goodsCollection/addCollection";
                    _url = "/m/g/goods/collection/1.0/collectGoods?flag=true";
                    _off = true;
                }

                G_JSON_POST(_url, {"goodsId":$(this).attr('goodsId')},function(data){
                    //if(data.status == "success"){
                    if(data.ret.code == "0"){
                        ShowTip(_off);
                        _off ? oBtn_collection.addClass('active') : oBtn_collection.removeClass('active');
                    }
                }, function () {}, function () {
                    clearTimeout(showTipTime);
                    showTipTime = setTimeout(function () {
                        ShowTip(false);
                        bOff = true
                    }, 2000);
                });

            }

            e.stopPropagation();
        })

        function ShowTip(off) {
            if(off) {
                oTip_collection.show().stop().animate({
                    'opacity': 1
                },500);
            }
            else {
                oTip_collection.stop().animate({
                    'opacity': 0
                },500, function () {
                    oTip_collection.hide();
                });
            }
        }

        oIconBtn.on('click', function (e) {
            if(oIconBtn.hasClass('on')) {
                oIconBtn.removeClass('on');
                IconListShow (false);
            }
            else {
                oIconBtn.addClass('on');
                IconListShow (true);
            }
            e.stopPropagation();
        })


        // 消息和功能点的展示和消失
        function IconListShow (off) {
            if(off) {
                oIconList.show().stop().animate({
                    'opacity': 1
                },500);
            }
            else {
                oIconList.stop().animate({
                    'opacity': 0
                },500, function () {
                    oIconList.hide();
                });
            }
        }

        oleaderShare.on('click',function () {
            oleaderBg.fadeIn();
        });
        oleaderBg.on('click',function () {
            oleaderBg.fadeOut();
        });
    }
